package testcase;

import static org.junit.Assert.*;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;

import org.junit.Test;

import controller.RecordController;
import dataStructure.LinkedList;
import entity.FileAsso;
import entity.Record;
import controller.FileIOController;

public class TestRecordController {
	private LinkedList<Record> list = new LinkedList<Record>();
	private FileIOController fileIO = new FileIOController();
	private RecordController recordController;
	
	public TestRecordController () throws SecurityException, IllegalArgumentException, NullPointerException, IOException, ParseException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException{
		fileIO.getFileAssoList().addContent(new FileAsso("record", "record.txt"));
		fileIO.inputData(list, "record");
		recordController = new RecordController(list, null);
	}

	@Test
	// find exits record"000001"
	public void searchRecord_1() throws SecurityException, IllegalArgumentException, ParseException, NoSuchFieldException, IllegalAccessException, NullPointerException, NoSuchMethodException, InvocationTargetException{
		
		Record r = new Record("000002 2013-25-21 12 000003 TableTennis Chan TaiHo active");
		
		String expected = r.getContentStr();

		String result = recordController.searchRecord("000002").getContentStr();
		assertEquals(expected, result);
	}

	@Test
	// find not exits record"000005"
	public void searchRecord_2() throws SecurityException, IllegalArgumentException, ParseException, NoSuchFieldException, IllegalAccessException, NullPointerException, NoSuchMethodException, InvocationTargetException{
		Record result = recordController.searchRecord("000005");
		assertEquals(null, result);
	}

	@Test
	// worng input ( with less/more 6 digi)
	public void searchRecord_3() throws SecurityException, IllegalArgumentException, ParseException, NoSuchFieldException, IllegalAccessException, NullPointerException, NoSuchMethodException, InvocationTargetException{
		Record result = recordController.searchRecord("0005");
		assertEquals(null, result);
	}

	@Test
	// delete record that exits in file ,delete 000001
	// ** delect & search record can't check the same no. ,otherwise result will
	// worng
	public void deleteRecord_1() throws SecurityException, IllegalArgumentException, ParseException, NoSuchFieldException, IllegalAccessException, NullPointerException, NoSuchMethodException, InvocationTargetException, IOException{
		Boolean result = recordController.deleteRecord("000001");
		assertEquals(true, result);
	}

	@Test
	// delete record that not exits in file / worng record no.
	public void deleteRecord_2() throws SecurityException, IllegalArgumentException, NullPointerException, IOException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, ParseException{
		Boolean result = recordController.deleteRecord("000007");
		assertEquals(false, result);
	}
}
